package com.yanqu.road.server.cmd.activity.recallplayer;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.recallplayer.RecallPlayerModule;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_RECALL_PLAYER_UPDATE_USER_INFO_RESP, desc = "跨服返回最新绑定回归玩家消息")
public class UpdateBindUserInfoFromCrossRespCmd extends AbstractCommand {
    private long bindUserId;
    private UserBaseInfo userBaseInfo;
    private int operation;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        RecallPlayerProto.RecallPlayerCrossGetUserInfoResp msg = RecallPlayerProto.RecallPlayerCrossGetUserInfoResp.parseFrom(packet.getBytes());
        ret = msg.getRet();
        bindUserId = msg.getRecallUserId();
        operation = msg.getOperation();
        if (msg.hasUserInfo()) {
            userBaseInfo = PlayerBasePb.parseToUserBaseInfo(msg.getUserInfo());
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (operation == 1) {
            player.getModule(RecallPlayerModule.class).sendUserInfoAndTaskData(bindUserId, userBaseInfo);
        } else if (operation == 2) {
            player.getModule(RecallPlayerModule.class).returnUserGetInfoByCode(ret, userBaseInfo);
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
